from math import pow

def surprise(p):
    for i in range(2,9999999):
        s = 0
        for j in map(int, str(i)):
            s += int(pow(j, p))
        if s == i:
            yield i
            
if __name__ == '__main__':
    t = 0
    for i in surprise(5):
        t += i
    print t
    